<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:nwisdocs="http://wales.nhs.uk/nwis/docs"
	exclude-result-prefixes="xs xsi">

  <xsl:template match="nwisdocs:DocumentBody/nwisdocs:DiagnosesAndProblems">
		<div class="boxed-section" id="{local-name()}">
      <h2>Diagnoses, problems</h2>
      <div style="margin:10px;font-style: italic;">
        The main issues identified or dealt with during this admission
      </div>
      <div class="inline-content">
        <xsl:choose>
          <xsl:when test="count(./*) &gt; 0">

            <table>
              <thead>
                <tr>
                  <td>Diagnosed On</td>
                  <td>Diagnoses/Problem</td>
                  <td>Suspected/Confirmed</td>
                  <td>New</td>
                  <td>Resolved</td>
                  <td>Recorded On</td>
                </tr>
              </thead>
              <xsl:for-each select="nwisdocs:DischargeDiagnosis">
                <tr>
                  <xsl:if test="position() mod 2 = 0">
                    <xsl:attribute name="class">alt-row</xsl:attribute>
                  </xsl:if>
                  <td>
                    <xsl:call-template name="standard_date">
                      <xsl:with-param name="date" select="nwisdocs:ThisDiagnosis/nwisdocs:EffectiveTime/nwisdocs:Start/nwisdocs:Date"/>
                    </xsl:call-template>
                  </td>
                  <td>
                    <xsl:value-of select="nwisdocs:ThisDiagnosis/nwisdocs:Narrative"/>
                  </td>
                  <td>
                    <xsl:value-of select="nwisdocs:ThisDiagnosis/nwisdocs:Status"/>
                  </td>
                  <td>
                    <xsl:value-of select="nwisdocs:ThisDiagnosis/@isNew"/>
                  </td>
                  <td>
                    <xsl:value-of select="nwisdocs:ThisDiagnosis/@isResolved"/>
                  </td>
                  <td>
                    <xsl:call-template name="standard_date">
                      <xsl:with-param name="date" select="nwisdocs:ThisDiagnosis/nwisdocs:RecordedAt/nwisdocs:Date"/>
                    </xsl:call-template>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
          </xsl:when>
          <xsl:otherwise>None recorded</xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
	</xsl:template>
		
</xsl:stylesheet>
